<?php

namespace App\Kuafu\Mqtt\Controller\Pos;

use App\Kuafu\Base\Controller\BaseController;
use App\Kuafu\Mqtt\Model\Log;
use App\Kuafu\Mqtt\Service\MqttService;
use App\Kuafu\User\Service\AuthService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class QueueController extends BaseController
{
    /**
     * 获取队列
     * @throws \App\Kuafu\WaiMai\Exceptions\WaiMaiException
     */
    public function getQueue(Request $request)
    {
        $result = (new MqttService($this->brandId, $this->shopId))->popQueue();
        return $this->success($result);
    }

    /**
     * 设置队列日志状态
     *
     * @param Request $request
     * @return JsonResponse
     */
    public function setLogStatus(Request $request)
    {
        $ids      = $request->post('ids');
        $errorIds = $request->post('errorIds');

        if (is_array($ids) && count($ids) > 0) {
            Log::setStatus($ids, Log::STATUS_FINISHED);
        }

        if (is_array($errorIds) && count($errorIds) > 0) {
            Log::setStatus($errorIds, Log::STATUS_ERROR);
        }

        return $this->success(['result' => true]);
    }

}